package com.dearbinge.opentapi.content.inform;

import com.baomidou.mybatisplus.plugins.Page;
import com.dearbinge.data.api.inform.InformService;
import com.dearbinge.data.pojo.inform.Inform;
import com.dearbinge.utils.ResultMsg;
import com.dearbinge.utils.enums.ResultStatusCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
 * 举报模块控制层
 *
 * @author cl
 * @date 2019/3/15
 */
@Api(description = "举报模块")
@RestController
@RequestMapping("/inform")
@EnableAutoConfiguration
public class informController {

    @Autowired
    private InformService informService;

    @ApiOperation(value = "增加修改举报模块", notes = "增加修改举报模块")
    @RequestMapping(value = "/insertOrUpdateInform", method = RequestMethod.POST)
    public ResultMsg<String> insertOrUpdateInform(@RequestBody Inform inform) {
        try {
            Integer dataCode;
            if (inform.getId() == null || inform.getId() == 0) {
                dataCode = informService.insert(inform);
                if (dataCode > 0) {
                    return ResultMsg.ok("增加成功");
                }
            } else {
                dataCode = informService.update(inform);
                if (dataCode > 0) {
                    return ResultMsg.ok("修改成功");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(ResultStatusCodeEnum.CODE500.getCode(), ResultStatusCodeEnum.CODE500.getDesc());
    }

    /**
     * 查询举报列表
     */
    @ApiOperation(value = "查询举报列表", notes = "查询举报列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "页面数量", paramType = "query")
    })
    @RequestMapping(value = "/getInformList", method = RequestMethod.GET)
    public ResultMsg<Page> getUserInformList( Integer current, Integer size) {
        try {
            Page page = informService.getInformList(current, size);
            return ResultMsg.okData(page, ResultStatusCodeEnum.SUCCESS.getDesc());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(ResultStatusCodeEnum.CODE500.getCode(), ResultStatusCodeEnum.CODE500.getDesc());
    }

    /**
     * 查询指定用户的举报列表
     */
    @ApiOperation(value = "查询指定用户的举报列表", notes = "查询指定用户的举报列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "userId", paramType = "query", required = true),
            @ApiImplicitParam(name = "current", value = "当前页", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "页面数量", paramType = "query")
    })
    @RequestMapping(value = "/getUserInformList", method = RequestMethod.GET)
    public ResultMsg<Page> getUserInformList(String userId, Integer current, Integer size) {
        try {
            Page page = informService.getUserInformList(userId, current, size);
            return ResultMsg.okData(page, ResultStatusCodeEnum.SUCCESS.getDesc());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(ResultStatusCodeEnum.CODE500.getCode(), ResultStatusCodeEnum.CODE500.getDesc());
    }



}
